home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
FromTheMag
/
JW FLV MEDIA PLAYER 4.2
/
mediaplayer.exe
/
player.swf
/
scripts
/
com
/
jeroenwijering
/
models
/
CameraModel.as
next >
Wrap
Text File
|
2008-11-04
|
5KB
|
187 lines
package com.jeroenwijering.models
{
import com.jeroenwijering.events.ModelEvent;
import com.jeroenwijering.events.ModelStates;
import com.jeroenwijering.player.Model;
import flash.events.ErrorEvent;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.ObjectEncoding;
import flash.utils.clearInterval;
import flash.utils.setInterval;
public class CameraModel implements ModelInterface
{
private var stream:NetStream;
private var interval:Number;
private var connection:NetConnection;
private var camera:Camera;
private var model:Model;
private var microphone:Microphone;
private var position:Number;
private var video:Video;
public function CameraModel(param1:Model)
{
var mod:Model = param1;
super();
model = mod;
try
{
camera = Camera.getCamera();
microphone = Microphone.getMicrophone();
video = new Video(320,240);
}
catch(err:Error)
{
model.sendEvent(ModelEvent.ERROR,{"message":"No webcam found on this computer."});
}
connection = new NetConnection();
connection.objectEncoding = ObjectEncoding.AMF0;
connection.addEventListener(NetStatusEvent.NET_STATUS,statusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,errorHandler);
quality(model.config["quality"]);
}
public function stop() : void
{
position = 0;
video.attachCamera(null);
clearInterval(interval);
if(stream)
{
stream.publish(null);
}
}
public function pause() : void
{
video.attachCamera(null);
if(stream)
{
stream.publish(null);
stream.attachAudio(null);
stream.attachCamera(null);
}
clearInterval(interval);
model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.PAUSED});
}
private function statusHandler(param1:NetStatusEvent) : void
{
if(param1.info.code == "NetConnection.Connect.Success")
{
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS,statusHandler);
play();
}
model.sendEvent(ModelEvent.META,{"info":param1.info.code});
}
public function volume(param1:Number) : void
{
}
private function errorHandler(param1:ErrorEvent) : void
{
model.sendEvent(ModelEvent.ERROR,{"message":param1.text});
}
public function load() : void
{
position = model.playlist[model.config["item"]]["start"];
model.mediaHandler(video);
if(model.config["streamer"])
{
connection.connect(model.config["streamer"]);
}
else
{
play();
}
}
private function timeInterval() : void
{
var _loc1_:* = undefined;
position = Math.round(position * 10 + 1) / 10;
_loc1_ = model.playlist[model.config["item"]]["duration"];
if(_loc1_ > 0)
{
if(position >= _loc1_)
{
clearInterval(interval);
model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.COMPLETED});
}
else
{
model.sendEvent(ModelEvent.TIME,{
"position":position,
"duration":_loc1_
});
}
}
}
public function play() : void
{
video.attachCamera(camera);
model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.PLAYING});
interval = setInterval(timeInterval,100);
if(stream)
{
stream.publish(model.playlist[model.config["item"]]["file"]);
stream.attachAudio(microphone);
stream.attachCamera(camera);
}
}
public function seek(param1:Number) : void
{
position = param1;
clearInterval(interval);
play();
}
public function quality(param1:Boolean) : void
{
if(param1 == true)
{
camera.setMode(480,360,25);
video.smoothing = true;
video.deblocking = 4;
model.sendEvent(ModelEvent.META,{
"framerate":25,
"height":360,
"width":480
});
}
else
{
camera.setMode(240,180,12);
video.smoothing = false;
video.deblocking = 1;
model.sendEvent(ModelEvent.META,{
"framerate":12,
"height":180,
"width":240
});
}
}
}
}